package com.dengcj.ecology.doc;

import com.dengcj.util.CjStrUtil;
import weaver.docs.webservices.DocAttachment;
import weaver.docs.webservices.DocInfo;
import weaver.docs.webservices.DocServiceImpl;
import weaver.hrm.User;

import java.util.List;

/**
 * @author dengchunjie
 * @Description: 文档工具类
 * @date 2022/1/11 17:15
 */
public class WeaDocUtil {

    /**
     * 创建ecology系统文档
     * @param user 用户
     * @param subject 文档标题
     * @param content 文档内容
     * @param seccatetory 目录ID
     * @param filename 附件文件名
     * @param fileBase64Str 附件Base64
     * @return
     */
    public int create(User user, String subject, String content, int seccatetory, String filename, String fileBase64Str){

        try {
            fileBase64Str = CjStrUtil.SBC2DBC(fileBase64Str);
            DocServiceImpl docService = new DocServiceImpl();
            DocInfo doc = new DocInfo();
            DocAttachment da = new DocAttachment();

            da.setDocid(0);
            da.setImagefileid(0);
            da.setFilecontent(fileBase64Str);
            da.setIszip(1);
            da.setFilename(filename);
            da.setDocfiletype("3");

            doc.setDoccreaterid(user.getUID());//
            doc.setSeccategory(seccatetory);//子目录id
            doc.setOwnerid(user.getUID());
            doc.setDocStatus(1);
            doc.setId(0);
            doc.setDocType(2);
            doc.setDocSubject(subject);
            doc.setDoccontent(content);
            doc.setAttachments(new DocAttachment[] { da });
            return docService.createDocByUser(doc, user);
        }catch (Exception e){
            e.printStackTrace();
        }

        return -1;
    }

    /**
     * 创建ecology系统文档
     * @param user 用户
     * @param subject 文档标题
     * @param content 文档内容
     * @param seccatetory 目录ID
     * @param attachments 附件List
     * @return
     */
    public int create(User user, String subject, String content, int seccatetory, List<DocAttachment> attachments){
        try {
            DocServiceImpl docService = new DocServiceImpl();
            DocInfo doc = new DocInfo();

            doc.setDoccreaterid(user.getUID());//
            doc.setSeccategory(seccatetory);//子目录id
            doc.setOwnerid(user.getUID());
            doc.setDocStatus(1);
            doc.setId(0);
            doc.setDocType(2);
            doc.setDocSubject(subject);
            doc.setDoccontent(content);
            doc.setAttachments(attachments.toArray(new DocAttachment[attachments.size()]));
            return docService.createDocByUser(doc, user);
        }catch (Exception e){
            e.printStackTrace();
        }

        return -1;
    }
}
